﻿using PRO.Admin;
using PRO.Public;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using PRO.Common;
using PRO.CashCoupon;

namespace web.Manage.Cash_coupon
{
    public partial class _default : ManageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
                Bind();
        }
        private void Bind()
        {
            int counts = 0;
            int pages = 0;
            this.Pager1.PageSize = 12;
            DataTable dt = PublicLib.CutPage("Pro_CashCoupon", "id", "id desc", this.Pager1.PageIndex, this.Pager1.PageSize, "id,cardnumber,cashprice,status,createtime,usetime", "", "", out pages, out counts);
            this.Pager1.RecordCount = counts;
            this.Repeater1.DataSource = dt;
            this.Repeater1.DataBind();
        }
        protected string GetStatus(object status)
        {
            string str = null;
            switch (status.ToString())
            { 
                case "0":
                    str = "未售出";
                    break;
                case "1":
                    str = "已售出";
                    break;
                case "2":
                    str = "已使用";
                    break;
            }
            return str;
        }

        protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            int id = e.CommandArgument.ToInt(0);
            if (id > 0)
            {
                switch (e.CommandName)
                { 
                    case "status":
                        CashCouponLib.SetSoldOver(id);
                        break;
                    case "del":
                        CashCouponLib.DelCashCoupon(id);
                        break;
                }
            }
            Bind();
        }

        protected void Pager1_PageIndexChanging(object sender, PRO.Controls.Pager.NumericaArgs e)
        {
            this.Pager1.PageIndex = e.NewPageIndex;
            Bind();
        }
    }
}